/*
 *  Copyright (C) 2010 Glauco
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.swing.commons;

import java.lang.reflect.Method;
import java.util.logging.Level;
import org.balisunrise.application.Application;
import org.balisunrise.common.Event;

/**
 *
 * @author Glauco
 */
public class DirectVisualAction extends VisualAction{

    /**
     * Instância do Mapa de ações
     */
    Object map;

    public DirectVisualAction(Object map, Method method, boolean withParm) {
        this.map = map;
        setMethod(method);
        setWithParm(withParm);
    }

    public void setMap(Object map) {
        this.map = map;
    }

    public Object getMap() {
        return map;
    }

    @Override
    public void perform(Event evt) {

        try{
            if(isWithParm())
                method.invoke(map, evt);
            else
                method.invoke(map);
        } catch(Exception ex){

            String msg = "Action can not be performed." +
                    " MAP: " + map.toString()+
                    " METHOD: " + method.toString();

            Application.get().getLogger().log(Level.SEVERE, msg, ex);
        }
    }
}
